home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 013 / tparknot.arc / TIMPARK1.ASM < prev   
Encoding:
Assembly Source File  |  1986-10-09  |  8.1 KB  |  290 lines

  1.           PAGE    60,132
  2.           TITLE    TIMPARK1.ASM From File TPARK.ARC
  3.  
  4. ;    AUTHOR: Sanford Z. Zelovitz
  5. ;         714-894-6808
  6.  
  7. ;         Version 1.1, 03/19/86
  8. ;
  9. ;    A resident program to park drive C and, if present, drive D
  10. ;    after a delay of N minutes.
  11. ;
  12. ;    To use the program, simply type or put in your batch file:
  13. ;        TIMEPARK  N
  14. ;
  15. ;                  where N is the number of minutes that you
  16. ;                  will allow before the disk parking takes
  17. ;                  place.  Please note that the range of N is 1-9.
  18. ;
  19. ;    I excerpted the documentation and annoted the program
  20. ;    Lew Paper, 10/9/86
  21.  
  22. code    Segment Para
  23.     Assume cs:code, ds:code
  24.     org    100h
  25. park    proc far
  26.     jmp    init    ; Initialize
  27.  
  28. ;********************************************************************
  29.  
  30. ;    VARIABLES FOR RESIDENT PORTION
  31.  
  32. x1coff     dw    0    ; Original timer interrupt 1CH offset
  33. x1cseg     dw    0    ; Original timer interrupt 1CH segment
  34. x13off     dw    0    ; Original disk  interrupt 13H offset
  35. x13seg     dw    0    ; Original disk  interrupt 13H offset
  36. parked    dw    0    ; 1 if there was a parking request and
  37.             ; there has been no disk request since
  38. count    dw    0    ; Number of timer ticks without a
  39.             ; disk request left before the system
  40.             ; issues a parking request
  41. value    dw    0    ; Total number of timer ticks without
  42.             ; a disk request before the system
  43.             ; issues a parking request
  44. flag    dw    0    ; 1 if the system is parking a head
  45. oldax    dw    0    ; Storage for original AX when parking
  46. oldip    dw    0    ; Storage for original IP when parking
  47. oldcs    dw    0    ; Storage for original CS when parking
  48. oldflgs    dw    0    ; Storage for original flags when
  49.             ; parking
  50.  
  51. ;********************************************************************
  52.  
  53. ;     TIMER INTERRUPT 1CH
  54.  
  55.     even
  56. x1cint:    push    ax      ; Save registers used on stack
  57.     push    bx
  58.     push    cx
  59.     push    dx
  60.     push    ds
  61.     mov    ax,cs    ; Establish value of DS
  62.     mov    ds,ax
  63.     xor    ax,ax    ; 0 => AX
  64.     cmp    parked,ax    ; Has the disk been parked?
  65.     jne    x1cext    ; Yes.  Go on to next timer function.
  66.     dec    word ptr count    ; Number of timer ticks idle until park
  67.             ; => count
  68.     cmp    count,ax    ; Should we park now?
  69.     jne    x1cext    ; No.  Go on to next timer function
  70.     cmp    flag,1    ; Are we parking now?
  71.     je    x1cext    ; Yes.  Go on to next timer function
  72.  
  73. ;    Set up parking
  74.     cli        ; Enable interrupts
  75.     mov    ax,1    ; 1 => AX
  76.     mov    parked,ax    ; Show we are parked
  77.     mov    flag,ax    ; Show we are parking
  78.     mov    ax,value    ; Reset count to number of timer ticks
  79.             ; idle until park
  80.     mov    count,ax
  81.     pop    ds    ; Restore registers to conditions at
  82.             ; start of interrupt
  83.     pop    dx
  84.     pop    cx
  85.     pop    bx
  86.     pop    ax
  87.     mov    cs:oldax,ax    ; Save so we can use AX to receive
  88.             ; stack
  89. ;    Now save the three words from the original interrupt call in memory
  90.     pop    ax    ;ip
  91.     mov    cs:oldip,ax
  92.     pop    ax          ;cs
  93.     mov    cs:oldcs,ax
  94.     pop    ax          ;flags
  95.     mov    cs:oldflgs,ax
  96. ;    Generate an interrupt return to the parker
  97.     mov    ax,offset parks
  98.     pushf
  99.     push    cs
  100.     push    ax
  101.     mov    ax,cs:oldax    ; Restore AX to its value before the
  102.             ; interrupt
  103.     sti        ; Enable interrupts
  104.     jmp    dword ptr cs:[x1coff]    ; Go on to the next timer function
  105.             ; Will return to parks
  106.  
  107. x1cext:    jmp    x1cout    ; Target for short jumps on the way
  108.             ; to the next timer function
  109.  
  110. ;    Actually park
  111. ;    Note that registers are from the original interrupt call
  112. parks:    sti              ; Enable interrupts
  113.     push    ax    ; Save registers
  114.     push    cx
  115.     push    dx
  116.     push    ds
  117.     mov    ax,cs    ; Establish value of DS
  118.     mov    ds,ax
  119. ;
  120. ;
  121. ;    Do the BIOS's dirty work so this code will work!
  122. ;
  123.     mov    al,020h    ; 8259 end of interrupt command
  124.     out    020h,al
  125. ;
  126. ;
  127. ;
  128.     mov    ah,08    ; Return parameters from disk table
  129.     mov    dx,80h    ; Disk C:
  130.     int    13h    ; Disk interrupt
  131.     mov    dx,80h    ; Disk C:
  132. ;    The last useable cylinder is a 10 bit number.  CH contains its
  133. ;    low order 8 bits.  Bits 7 and 8 of CL contain its high order 2 
  134. ;    bits.
  135.      inc    ch    ; Get first unuseable cylinder number
  136.     jnc    p1
  137.     add    cl,40h    ; Add carry to ninth bit
  138. p1:    mov    ax,0c01h    ; Seek first unuseable sector
  139.     int    13h    ; Disk interrupt
  140. ;
  141.     mov    ah,08    ; Return parameters from disk table
  142.     mov    dx,81h    ; Disk D:
  143.     int    13h    ; Disk interrupt
  144.     mov    dx,81h    ; Disk D:
  145.       inc    ch    ; Get first unuseable cylinder number
  146.     jnc    p2
  147.     add    cl,40h    ; Add carry to ninth bit
  148. p2:    mov    ax,0c01h    ; Seek first unuseable sector
  149.     int    13h    ; Disk interrupt
  150. ;
  151.     xor    ax,ax    ; 0 => AX
  152.     mov    flag,ax    ; Show that we are not parking
  153.     pop    ds    ; Restore registers from original
  154.             ; call
  155.     pop    dx
  156.     pop    cx
  157.     mov    ax,cs:oldflgs    ; Restore original flags
  158.     push    ax
  159.     popf
  160.     pop    ax    ; Restore original AX
  161.      jmp    dword ptr cs:[oldip]    ; Effectively a FAR RETURN to the
  162.             ; original interrupt call
  163.  
  164. ;    Go on to the next timer function if no park
  165. x1cout:    pop    ds    ; Restore registers
  166.     pop    dx
  167.     pop    cx
  168.     pop    bx
  169.     pop    ax
  170. x1cou1:    jmp    dword ptr cs:[x1coff]    ; Go on to the next timer function
  171.  
  172. ;********************************************************************
  173.  
  174. ;    DISK INTERRUPT 13H
  175.  
  176. x13int:    push    ax    ; Save registers
  177.     push    ds
  178.     sti        ; Enable interrupts
  179.     mov    ax,cs    ; Establish value of DS
  180.     mov    ds,ax
  181.     cmp    flag,1    ; Are we parking?
  182.     je    x13in1    ; Yes.  Assume this is a call from
  183.             ; parking and go on to the next
  184.             ; disk function
  185.     mov    ax,value    ; Reset count to number of timer ticks
  186.             ; until park
  187.  
  188.     mov    count,ax
  189.     xor    ax,ax    ; 0 => AX
  190.     mov    parked,ax    ; Show we are not parked
  191. x13in1:    pop    ds    ; Restore registers
  192.     pop    ax
  193.     jmp    dword ptr cs:[x13off]    ; Go on to next disk function
  194.     dw    0
  195. table    dw    0    ; End of resident part
  196.  
  197. ;********************************************************************
  198.  
  199. ;    INITIALIZATION
  200.  
  201. init:    xor    ax,ax    ; 0 => AX
  202.     mov    parked,ax    ; Show we are not parked
  203.     mov    bx,80h    ; Address of count of command line
  204.             ; characters
  205.     mov    al,[bx]    ; Count of command line characters
  206.     cmp    al,0    ; Is command line empty?
  207.     jne    init1    ; No.  Get first character
  208.     int    21h    ; Return.  Note that there is no
  209.             ; explicit warning of the failure,
  210.             ; only the lack of a sign on message.
  211.  
  212. init1:    inc    bx    ; Address of next command line
  213.             ; character
  214.     mov    al,[bx]    ; Next command line character
  215.     cmp    al,32    ; Is it a space?
  216.     je    init1    ; Yes.  Get next command line
  217.             ; character
  218.     cmp    al,13    ; Is it a carriage return, which
  219.             ; marks the end of the command line?
  220.     jne    init3    ; No.  Get number of minutes to wait
  221. init2:    xor    ax,ax    ; 0 => AX
  222.     int    21h    ; Return with no message
  223.  
  224. init3:    cmp    al,49    ; Is it less than ASCII 1?
  225.     jb    init2    ; Yes.  Return with no message.
  226.     cmp    al,57    ; Is it greater than ASCII 9?
  227.     ja    init2    ; Yes.  Return with no message.
  228.     lea    dx,mess    ; Offset of sign on message
  229.     mov    cx,ax    ; Temporarily save ASCII digit
  230.     mov    ah,09    ; Print string function
  231.     int    21h
  232.     mov    ax,cx    ; Restore ASCII digit
  233.     xor    ah,ah    ; 0 => AH
  234.     mov    bx,0fh    ; Converted digit to AX
  235.     and    ax,bx
  236.     mov    dx,1091    ; 60 * 18.2 = Number of timer ticks
  237.             ; per minute
  238.     mul    dx    ; Number of timer ticks idle until
  239.             ; park => AX
  240.     mov    value,ax    ; Number of timer ticks idle until
  241.             ; park => value
  242.     mov    count,ax    ; Number of timer ticks idle until
  243.             ; park => count
  244.  
  245.     cli        ; Disable interrupts
  246.     push    es    ; Save register
  247.     xor    ax,ax    ; 0 => AX
  248.     mov    es,ax    ; 0 => ES
  249.     mov    bx,76    ; 4 * 13H
  250.     mov    ax,es:[bx]    ; Offset of interrupt 13H => x13off
  251.     mov    x13off,ax    
  252.     mov    ax,offset x13int    ; Offset of x13int =>
  253.             ; offset of interrupt 13H
  254.     mov    es:[bx],ax
  255.     inc    bx    ; Offset of segment of interrupt
  256.             ; 13H => BX
  257.     inc    bx
  258.     mov    ax,es:[bx]    ; Segment of interrupt 13H => x13seg
  259.     mov    x13seg,ax
  260.     mov    ax,cs    ; CS => segment of interrupt 13H
  261.     mov    es:[bx],ax
  262.     xor    ax,ax    ; 0 => AX
  263.     mov    flag,ax    ; Show that we are not parking
  264.     mov    es,ax    ; 0 => ES
  265.     mov    bx,112    ; 4 * 1CH
  266.     mov    ax,es:[bx]    ; Offset of interrupt 1CH => x1coff
  267.     mov    x1coff,ax
  268.     mov    ax,offset x1cint    ; Offset of x1cint =>
  269.             ; offset of interrupt 1CH
  270.     mov    es:[bx],ax
  271.     inc    bx    ; Offset of segment of interrupt
  272.             ; 1CH => BX
  273.     inc    bx
  274.     mov    ax,es:[bx]    ; Segment of interrupt 1CH => x1cseg
  275.     mov    x1cseg,ax
  276.     mov    ax,cs    ; CS => segment of interrupt 1CH
  277.     mov    es:[bx],ax
  278.     pop    es    ; Restore register
  279.     sti        ; Enable interrupts
  280.     mov    dx,offset table    ; Last offset to retain
  281.     int    27h    ; Terminate and stay resident
  282.  
  283. ;    INITIALIZATION VARIABLE
  284. mess    db    'Alpha Computer Service timed parker is activated'
  285.     db    13,10,'for hard disks C and, if present, D'
  286.     db    13,10,'$'
  287. park    endp
  288. code    ends
  289.     end park
  290.